package com.songtai.action.admin.message;

import java.io.PrintWriter;

import com.songtai.action.SongtaiActionSupport;
import com.songtai.po.Message;
import com.songtai.service.MessageService;
import com.songtai.util.CommenUtil;
import com.songtai.util.Constants;
import com.songtai.util.Pager;

/**
 * @author 赵中杨
 * @email zhaozhongyang717@gmail.com
 * @date 2010 2010-4-20 下午04:27:54
 */
public class MessageAction extends SongtaiActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7254446796896341064L;
	private static final String CONTENT_TYPE = "text/html; charset=utf-8";
	private String nodeid;
	private Pager<Message> message;
	private String mid;
	private MessageService messageService;
	private int currentPage;

	public String getMsg() throws Exception {
		if (currentPage < 1) {
			currentPage = 1;
		}
		message = messageService.getAllMessage(currentPage, Constants.DEFAULT_PAGESIEZE);
		return SUCCESS;
	}

	public String deleteMsg() throws Exception {
		response.setContentType(CONTENT_TYPE);
		PrintWriter out = response.getWriter();
		if (CommenUtil.isEmpty(mid)) {
			out.print("error");
			return null;
		}
		messageService.deleteMessage(mid);
		out.print("success");
		return null;
	}

	/**
	 * @return the nodeid
	 */
	public String getNodeid() {
		return nodeid;
	}

	/**
	 * @param nodeid
	 *            the nodeid to set
	 */
	public void setNodeid(String nodeid) {
		this.nodeid = nodeid;
	}

	/**
	 * @return the message
	 */
	public Pager<Message> getMessage() {
		return message;
	}

	/**
	 * @param message
	 *            the message to set
	 */
	public void setMessage(Pager<Message> message) {
		this.message = message;
	}

	/**
	 * @return the mid
	 */
	public String getMid() {
		return mid;
	}

	/**
	 * @param mid
	 *            the mid to set
	 */
	public void setMid(String mid) {
		this.mid = mid;
	}

	/**
	 * @return the messageService
	 */
	public MessageService getMessageService() {
		return messageService;
	}

	/**
	 * @param messageService
	 *            the messageService to set
	 */
	public void setMessageService(MessageService messageService) {
		this.messageService = messageService;
	}

	/**
	 * @return the currentPage
	 */
	public int getCurrentPage() {
		return currentPage;
	}

	/**
	 * @param currentPage
	 *            the currentPage to set
	 */
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

}
